home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * ファイル情報の読み取り
- *************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
-
- #include <silib.h>
- #include <sifs.h>
- #include "sdkfs.h"
- #include "sdkfscf.h"
-
- /*************************************************************************
- * ファイル情報の初期化
- *************************************************************************/
-
- void FileSel_clearFndat( FILESEL_T *fs )
- {
- FNDAT_T *fndat, *next;
-
- fndat = fs->fnTop;
- while ( fndat )
- {
- next = fndat->next;
- SI_FREE(fndat);
- fndat = next;
- }
- fs->fnTop = NULL;
-
- if ( fs->fnMat )
- SI_FREE(fs->fnMat);
- fs->fnMat = NULL;
-
- fs->numFn = fs->numMat = fs->posDspTop = 0;
- fs->posMark = -1;
- }
-
-
- static FNDAT_T *readdir(void)
- {
- int ret;
- REG FNDAT_T *fndat;
- static int opflg = FALSE;
- static int no;
- static struct find_t fbuf;
-
- if ( opflg == FALSE ) /* 初回コール */
- {
- ret = _dos_findfirst( "*.*", 0x16, &fbuf);
- opflg = TRUE;
- no = 0;
- } else
- ret = _dos_findnext( &fbuf );
-
- if ( ret ) /* error */
- {
- opflg = FALSE;
- return (NULL);
- }
-
- if ( (fndat = SI_MALLOC(sizeof(FNDAT_T))) != NULL )
- {
- fndat->next = NULL;
- fndat->no = no++;
- fndat->flag = FALSE;
- fndat->mark = FALSE;
- fndat->buf = fbuf;
- if ( !(fndat->buf.attrib & FSATT_DIR) )
- FS_strlwr( fndat->buf.name ); /* 小文字に変換 */
- }
- return (fndat);
- }
-
- /*************************************************************************
- * ディレクトリ情報の読み取り
- *************************************************************************/
-
- int FileSel_readdir( FILESEL_T *fs )
- {
- FNDAT_T *fndat;
-
- FileSel_clearFndat( fs );
-
- {
- long totalFree, writeFree;
-
- if ( FS_getDskFree( fs->drv, &totalFree, &writeFree) )
- {
- fs->err = FSERR_DRIVE;
- return (ERR);
- }
- }
-
- while ( (fndat = readdir()) != NULL )
- {
- ++(fs->numFn);
- if ( fs->fnTop )
- {
- fndat->next = fs->fnTop;
- fs->fnTop = fndat;
- } else
- {
- fndat->next = NULL;
- fs->fnTop = fndat;
- }
- }
-
- return (NORMAL);
- }
-
-
- static int wildMatch( CONST char *s )
- {
- char buf[256];
-
- if ( strchr(s, '.') == NULL )
- { /* 拡張子は指定されていない */
- /* ピリオドだけ追加 */
- sprintf(buf,"%s%c",s, '.');
- return FS_wildMatch( buf );
- } else
- return FS_wildMatch( s );
- }
-
- /*************************************************************************
- * ファイルの選択(ワルイドカード)
- *************************************************************************/
-
- int FilsSel_pickup( FILESEL_T *fs )
- {
- int ai, argc;
- char **argv;
- char *wild;
-
- if ( fs->numFn == 0 )
- {
- fs->err = FSERR_FILE;
- return (ERR);
- }
- if ( fs->wild == NULL || (fs->wild && fs->wild[0] == '\0') )
- wild = "*.*";
- else
- wild = fs->wild;
-
- {
- FNDAT_T *fndat;
-
- fndat = fs->fnTop;
- while ( fndat )
- {
- fndat->flag = FALSE;
- fndat = fndat->next;
- }
- }
-
- if ( fs->fnMat )
- {
- SI_FREE(fs->fnMat);
- fs->fnMat = NULL;
- }
- fs->numMat = fs->posDspTop = 0;
-
- if ( SI_argSet( &argc, &argv, wild) )
- return (ERR);
- for ( ai = 0; ai < argc; ++ai )
- {
- FNDAT_T *fndat;
-
- FS_wildSet( argv[ai] );
- fndat = fs->fnTop;
- while ( fndat )
- {
- if( fndat->flag == FALSE )
- {
- if ( (fndat->buf.attrib & FSATT_DIR) || wildMatch( fndat->buf.name ) )
- {
- ++(fs->numMat);
- fndat->flag = TRUE;
- }
- }
- fndat = fndat->next;
- }
- FS_wildFree();
- }
- SI_argFree( argc, argv );
-
- if ( fs->numMat == 0 )
- {
- fs->err = FSERR_FILE;
- return (ERR);
- }
-
- if ( fs->numMat > 0 )
- { /* マッチしたファイル情報の設定 */
- FNDAT_T *fndat;
- int i = 0;
-
- if ( (fs->fnMat = SI_MALLOC(sizeof(FNDAT_T *) * fs->numMat)) == NULL )
- {
- fs->numMat = 0;
- fs->err = FSERR_MEMORY;
- return (ERR);
- }
-
- fndat = fs->fnTop;
- while ( fndat )
- {
- if ( fndat->flag )
- fs->fnMat[i++] = fndat;
- fndat = fndat->next;
- }
- }
- return (NORMAL);
- }
-
- int FileSel_changedir( FILESEL_T *fs )
- {
- fs->posMark = -1;
- fs->err = FSERR_NOERR;
-
- FS_chdir2( fs->whare );
- if ( FileSel_readdir( fs ) )
- return (ERR);
- if ( FilsSel_pickup( fs ) )
- return (ERR);
- FileSel_sort( fs );
-
- return (NORMAL);
- }
-